package com.base.cn.platform.os.controller.web.course.play.note;

import com.base.cn.platform.os.common.WebBaseController;
import com.base.cn.platform.os.service.course.note.CourseNoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Map;

/**
 * 课程笔记
 *
 * @author SK
 * @since 2018-06-19
 **/
@Controller
@RequestMapping("/web/uc/course/note")
public class WebCourseNoteController extends WebBaseController {

    @Autowired
    private CourseNoteService courseNoteService;

    /**
     * 加载课程评论列表
     *
     * @param note        课程笔记查询条件
     * @param currentPage 第N页
     * @return 课程评论列表
     */
    @RequestMapping("/ajaxCourseNoteList")
    public String ajaxCourseNoteList(HttpServletRequest request,
                                     Model model,
                                     @RequestBody Map<String, Object> note,
                                     @RequestParam(value = "currentPage", required = false, defaultValue = "1") Integer currentPage) {
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        note.put("userId", userId);
        Map<String, Object> dataMap = courseNoteService.findCourseNotePage(note, currentPage, null, false, false, false, true);
        model.addAttribute("dataMap",dataMap);
        return resultPage("/course/play/note/ajax-course-note-list");
    }

    /**
     * 保存课程笔记
     *
     * @param note 课程笔记
     * @return 保存结果
     */
    @RequestMapping("/saveCourseNote")
    @ResponseBody
    public Map<String, Object> saveCourseNote(HttpServletRequest request,
                                              @RequestBody Map<String, Object> note) {
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        note.put("userId", userId);
        return courseNoteService.saveCourseNote(note);
    }
}
